# -*- coding: utf-8 -*-
# !/usr/bin/env python
from fastapi import APIRouter
from starlette.requests import Request
from starlette.templating import Jinja2Templates
from starlette.responses import FileResponse
from starlette.staticfiles import StaticFiles
import os

router = APIRouter()
templates = Jinja2Templates(directory="templates")
router.mount("/static", StaticFiles(directory="./static"), name="static")


@router.get('/')
def index(request: Request):
    return templates.TemplateResponse('./tables/index.html', {'request': request})


@router.get('/table')
def table(request: Request, page: int = 0, limit: int = 10):
    data = [
        {"id": 10000, "username": "user-0", "sex": "女", "city": "城市-0", "sign": "签名-0", "experience": 255, "logins": 24,
         "wealth": 82830700, "classify": "作家", "score": 57},
        {"id": 10001, "username": "user-1", "sex": "男", "city": "城市-1", "sign": "签名-1", "experience": 884, "logins": 58,
         "wealth": 64928690, "classify": "词人", "score": 27},
        {"id": 10002, "username": "user-2", "sex": "女", "city": "城市-2", "sign": "签名-2", "experience": 650, "logins": 77,
         "wealth": 6298078, "classify": "酱油", "score": 31},
        {"id": 10003, "username": "user-3", "sex": "女", "city": "城市-3", "sign": "签名-3", "experience": 362,
         "logins": 157, "wealth": 37117017, "classify": "诗人", "score": 68},
        {"id": 10004, "username": "user-4", "sex": "男", "city": "城市-4", "sign": "签名-4", "experience": 807, "logins": 51,
         "wealth": 76263262, "classify": "作家", "score": 6},
        {"id": 10005, "username": "user-5", "sex": "女", "city": "城市-5", "sign": "签名-5", "experience": 173, "logins": 68,
         "wealth": 60344147, "classify": "作家", "score": 87},
        {"id": 10006, "username": "user-6", "sex": "女", "city": "城市-6", "sign": "签名-6", "experience": 982, "logins": 37,
         "wealth": 57768166, "classify": "作家", "score": 34},
        {"id": 10000, "username": "user-0", "sex": "女", "city": "城市-0", "sign": "签名-0", "experience": 255, "logins": 24,
         "wealth": 82830700, "classify": "作家", "score": 57},
        {"id": 10001, "username": "user-1", "sex": "男", "city": "城市-1", "sign": "签名-1", "experience": 884, "logins": 58,
         "wealth": 64928690, "classify": "词人", "score": 27},
        {"id": 10002, "username": "user-2", "sex": "女", "city": "城市-2", "sign": "签名-2", "experience": 650, "logins": 77,
         "wealth": 6298078, "classify": "酱油", "score": 31},
        {"id": 10003, "username": "user-3", "sex": "女", "city": "城市-3", "sign": "签名-3", "experience": 362,
         "logins": 157, "wealth": 37117017, "classify": "诗人", "score": 68},
        {"id": 10004, "username": "user-4", "sex": "男", "city": "城市-4", "sign": "签名-4", "experience": 807, "logins": 51,
         "wealth": 76263262, "classify": "作家", "score": 6},
        {"id": 10005, "username": "user-5", "sex": "女", "city": "城市-5", "sign": "签名-5", "experience": 173, "logins": 68,
         "wealth": 60344147, "classify": "作家", "score": 87},
        {"id": 10006, "username": "user-6", "sex": "女", "city": "城市-6", "sign": "签名-6", "experience": 982, "logins": 37,
         "wealth": 57768166, "classify": "作家", "score": 34}
    ]
    tables = {"code": 0, "msg": "", "count": len(data), "data": data[(page-1) * limit:page * limit]}
    return tables
